package com.wzq.design.business.base.product.controller;

import com.wzq.design.base.controller.CommController;
import com.wzq.design.base.dto.QueryByIdRequest;
import com.wzq.design.base.dto.RemoveRequest;
import com.wzq.design.business.base.product.dto.ProductRequest;
import com.wzq.design.business.base.product.dto.BaseProductDto;
import com.wzq.design.business.base.product.service.ProductService;
import com.wzq.ssm.parent.base.dto.JsonResult;
import com.wzq.ssm.parent.base.dto.Page;
import org.springframework.web.bind.annotation.*;

/**
 * @author wangzhiqiang
 * @since 2023/5/8 15:07
 */
@RestController
@RequestMapping("/sys/product")
public class ProjectController extends CommController {
    private final ProductService productService;

    public ProjectController(ProductService productService) {
        this.productService = productService;
    }


    @PostMapping("/list")
    public JsonResult<Page<BaseProductDto>> list(@RequestBody ProductRequest productRequest) {
        return JsonResult.success("查询成功", productService.list(productRequest));
    }


    @PostMapping("/delete")
    public JsonResult<?> delete(@RequestBody RemoveRequest request) {
        productService.deleteByIds(request.getIds());
        return JsonResult.success("删除成功");
    }

    @PostMapping("/save")
    public JsonResult<BaseProductDto> save(@RequestBody BaseProductDto request) {
        return JsonResult.success("保存成功", productService.save(request));
    }


    @GetMapping("/findById")
    public JsonResult<BaseProductDto> findById(QueryByIdRequest request) {
        return JsonResult.success("保存成功", productService.findById(request));
    }
}
